package org.walkerljl.boss.service.auth.impl;

import org.springframework.stereotype.Service;
import org.walkerljl.boss.dao.auth.AuthorizationDao;
import org.walkerljl.boss.domain.auth.Authorization;
import org.walkerljl.boss.support.dao.BaseDao;
import org.walkerljl.boss.support.enums.Status;
import org.walkerljl.boss.support.sdk.auth.enums.AuthObjectType;
import org.walkerljl.boss.enums.auth.AuthType;
import org.walkerljl.boss.service.auth.AuthorizationService;
import org.walkerljl.boss.support.service.impl.BaseServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * AuthorizationServiceImpl
 *
 * @author lijunlin
 */
@Service("authorizationService")
public class AuthorizationServiceImpl extends BaseServiceImpl<Long, Authorization> implements AuthorizationService {

    @Resource
    private AuthorizationDao authorizationDao;

    @Override
    public BaseDao<Long, Authorization> getDao() {
        return authorizationDao;
    }

    @Override
    public List<Authorization> queryPostAuthsByUserId(String userId) {
        Authorization condition = new Authorization();
        condition.setObjectType(AuthObjectType.USER.getValue());
        condition.setObjectId(userId);
        condition.setAuthType(AuthType.POST.getValue());
        condition.setStatus(Status.ENABLED.getValue());
        return selectList(condition);
    }

    @Override
    public List<Authorization> queryRoleAuthsByUserId(String userId) {
        Authorization condition = new Authorization();
        condition.setObjectType(AuthObjectType.USER.getValue());
        condition.setObjectId(userId);
        condition.setAuthType(AuthType.ROLE.getValue());
        condition.setStatus(Status.ENABLED.getValue());
        return selectList(condition);
    }
}